<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>抢筹</title>
		<link href="css/text.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="js/json2html.js"></script>
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script>		   
			window.onload = function() {									
			getSource("0");
			changeStyle();
			}
						
			function time_range(beginTime, endTime) {
				var strb = beginTime.split(":");
				if (strb.length != 2) {
					return false;
				}

				var stre = endTime.split(":");
				if (stre.length != 2) {
					return false;
				}

				var b = new Date();
				var e = new Date();
				var n = new Date();

				b.setHours(strb[0]);
				b.setMinutes(strb[1]);
				e.setHours(stre[0]);
				e.setMinutes(stre[1]);

				if (n.getTime() - b.getTime() > 0 && n.getTime() - e.getTime() < 0) {
					getSource("0");					
					console.log(true)　　　　　　
					return true;				
				} else {
					console.log(false)
				    return false;     
				}
			}　　　
   　　　
			$(function() {
				setInterval(function() {
				time_range("9:00","10:00")									
				},
				60000);
			})
			
			function changeStyle() {
				var obj1 = document.getElementById("towrite");				
				//obj1.style.width= "250px";	//左侧宽度
				obj1.style.fontSize="12px";	//左侧字体	  		  			 
			}	
			
			Date.prototype.Format = function (fmt) {
				var o = {
				"M+": this.getMonth() + 1, //月份
				"d+": this.getDate(), //日
				"h+": this.getHours(), //小时
				"m+": this.getMinutes(), //分
				"s+": this.getSeconds(), //秒
				"q+": Math.floor((this.getMonth() + 3) / 3), //季度
				"S": this.getMilliseconds() //毫秒
				};
				if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
				for (var k in o)
				if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
				return fmt;
			};
			
			function getLocalTime(nS) {			          
			return new Date(parseInt(nS) * 1000).Format("hh:mm:ss")}						
			
			function keepTwoDecimal(num) {  
               var result = parseFloat(num);  
               if (isNaN(result)) {  
                   //alert('传递参数错误，请检查！');  
                   return false;  
               }  
               result = Math.round(num * 100) / 100;  
               return result;  
			};
			
			function createXmlHttp() {
				if (window.XMLHttpRequest) {
				xmlHttp = new XMLHttpRequest();
				} else {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
				}				
			}
			
			var t = "";
			function getSource(ss) {
				t = ss;
				var url = "http://excalc.icfqs.com:7616/TQLEX?Entry=HQServ.hq_nlp"; 	                			
				createXmlHttp();
				//早盘				
				var array1 = [{"funcId":20,"offset":0,"count":50,"sort":1,"period":0,"Token":"6679f5cadca97d68245a086793fc1bfc0a50b487487c812f","modname":"JJQC"}]
				//尾盘
				var array2 = [{"funcId":20,"offset":0,"count":50,"sort":1,"period":1,"Token":"6679f5cadca97d68245a086793fc1bfc0a50b487487c812f","modname":"JJQC"}]								
				xmlHttp.onreadystatechange = writeSource;
				xmlHttp.open("POST", url, true);				
				xmlHttp.setRequestHeader("User-Agent","TdxW");
				
				if(ss == "0")
					{	
						xmlHttp.send(JSON.stringify(array1)) ;						
					}
				if(ss == "1")
					{											
						xmlHttp.send(JSON.stringify(array2)) ; 						
					}						
			}
								
			var dms = "";
			function writeSource() { 			
				if (xmlHttp.readyState == 4) { 	
					var data = xmlHttp.responseText						
					//document.write(data);					
					var html = "";												
					if(data.indexOf("\"datas\": []") == -1)
					{											
						data = data.replace(/ /g,"").match(/\"datas\":\[(\S*)\]\}/)[1];	
						data = data.replace(/(\[).*?(?=\])/g,function(word){ 
						str = word.match(/\[(\S*)/)[1]; 
						return '{"code":' + str.split(',')[0] + 
						',"name":' + str.split(',')[1] + 
						',"kpje":' + str.split(',')[4] + 
						',"fd":' + str.split(',')[5] +
						',"wtje":' + str.split(',')[6] +
						',"cjje":' + str.split(',')[7];
						});
						data = "{\"data\":[" + data.replace(/\],\{/g,"},{").replace(/\]/g,"}]}");
						//document.write(data);
						//开盘金额				
						data = data.replace(/(\"kpje\":).*?(?=,)/g, function(word){ 						
						str = word.match(/\"kpje\":(\S*)/)[1];
							if(keepTwoDecimal(str/100000000) >= 1)
							{
								return '\"kpje\":\"' + keepTwoDecimal(str/100000000) + '亿\"';
							}
							else
							{
								return '\"kpje\":\"' + Math.round(str/10000) + '万\"';
							}
													
						}); 
						
						//抢筹委托金额				
						data = data.replace(/(\"wtje\":).*?(?=,)/g, function(word){ 						
						str = word.match(/\"wtje\":(\S*)/)[1];
							if(keepTwoDecimal(str/100000000) >= 1)
							{
								return '\"wtje\":\"' + keepTwoDecimal(str/100000000) + '亿\"';
							}
							else
							{
								return '\"wtje\":\"' + Math.round(str/10000) + '万\"';
							}
													
						});
						
						//抢筹成交金额				
						data = data.replace(/(\"cjje\":).*?(?=})/g, function(word){ 						
						str = word.match(/\"cjje\":(\S*)/)[1];
							if(keepTwoDecimal(str/100000000) >= 1)
							{
								return '\"cjje\":\"' + keepTwoDecimal(str/100000000) + '亿\"';
							}
							else
							{
								return '\"cjje\":\"' + Math.round(str/10000) + '万\"';
							}
													
						});

						//抢筹幅度				
						data = data.replace(/(\"fd\":).*?(?=,)/g, function(word){ 				
							str = word.match(/\"fd\":(\S*)/)[1]; 					
							return '\"fd\":"' + keepTwoDecimal(str*100) + '%"';
						});  				
						
						//document.write(data);
						
						var transform_aa = [           
						{"tag":"p", children:function(){return(json2html.transform(this.data, transform_bb));}}
						];
						
						var transform_bb= 
						{"tag":"p", children:[
						{"tag":"p", children:[											
						//{"tag": "li", "html":"<a href='http://www.treeid/code_${code}' >${code} ${name}&nbsp;&nbsp;开(收)盘金额：${kpje}&nbsp;&nbsp;抢筹幅度：${fd}&nbsp;&nbsp;抢筹委托金额：${wtje}&nbsp;&nbsp;抢筹成交金额：${cjje}</a>"}, 							
						{"tag":"li", children:function(){
						var ks = "";
						if(t == "0")
						{							
							ks = "开盘金额";
						}
						else
						{							
							ks = "收盘金额";
						}									
						return("<a href=http://www.treeid/code_" + 
						this.code + ">" + 						
						this.code + "&nbsp;" + 
						this.name + "&nbsp;&nbsp;" + 
						ks + "：" + this.kpje + "&nbsp;&nbsp;" +
						"抢筹幅度：" + this.fd + "&nbsp;&nbsp;" +
						"抢筹委托金额：" + this.wtje + "&nbsp;&nbsp;" +
						"抢筹成交金额：" + this.cjje +"</a>");											
						}}]}]}; 
						html = json2html.transform(data, transform_aa);																		
					}
					else
					{
						html = "暂无数据"
					}
					var zp = "<a href='javascript:void(0)' onclick='getSource(" + "\"0\"" + ")'>" + "早盘抢筹" + "</a>";
					var wp = "<a href='javascript:void(0)' onclick='getSource(" + "\"1\"" + ")'>" + "尾盘抢筹" + "</a>";				
					div1 = document.getElementById('towrite');
					div1.innerHTML = "<p>" + zp + "&nbsp;&nbsp;&nbsp;&nbsp;" + wp + "</p>";
					if(t == "0")
						{							
							div1.innerHTML = div1.innerHTML + '<h4>早盘抢筹</h4>';
						}
					else
						{							
							div1.innerHTML = div1.innerHTML + '<h4>尾盘抢筹</h4>';
						}							
					div1.innerHTML = div1.innerHTML + html;		
				}				
			}
			
			
		</script>
	</head>
	<body>
		<div id="towrite"></div>
	</body>
</html>